package com.ruoyi.web.controller.book;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.business.CmFtpFileBusiness;
import com.ruoyi.module.domain.FtpFile;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * ftp文件列Controller
 * 
 * @author ruoyi
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/file")
@RequiredArgsConstructor
public class CmFtpFileController extends BaseController
{
    private final CmFtpFileBusiness cmFtpFileBusiness;

    /**
     * 查询ftp文件列列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate timestamp)
    {
        startPage();
        List<FtpFile> list = cmFtpFileBusiness.selectCmFtpFileList(timestamp);
        return getDataTable(list);
    }

    /**
     * 获取ftp文件列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmFtpFileBusiness.selectCmFtpFileById(id));
    }

    /**
     * 新增ftp文件列
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "ftp文件列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FtpFile cmFtpFile)
    {
        return toAjax(cmFtpFileBusiness.insertCmFtpFile(cmFtpFile));
    }

    /**
     * 修改ftp文件列
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "ftp文件列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FtpFile cmFtpFile)
    {
        return toAjax(cmFtpFileBusiness.updateCmFtpFile(cmFtpFile));
    }

    /**
     * 删除ftp文件列
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "ftp文件列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(cmFtpFileBusiness.deleteCmFtpFileByIds(ids));
    }
}
